﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TVShows.DataModels;
using System.Data.Entity.Migrations;

namespace TVShows.Data
{
    public class Seeder
    {
        public static void Seed(ApplicationDbContext db, bool seedTVShows = true, bool seedCharacters = true)
        {
            if (seedTVShows)
            {
                //AddOrUpdate needs to use System.Data.Entity.Migrations
                db.TVShows.AddOrUpdate(
                    p => p.Name,
                    new TVShow { Name = "The Simpsons", Image = "http://images.musictimes.com/data/images/full/7821/the-simpsons.png" },
                    new TVShow { Name = "The Office", Image="http://www.episodegenerator.com/wp-content/uploads/the_office_wallpaper_1280x1024_2.jpg" },
                    new TVShow { Name = "The Big Bang Theory", Image="http://images8.alphacoders.com/431/431311.jpg"}
                    );
                db.SaveChanges();
            }

            if (seedCharacters)
            {
                db.Characters.AddOrUpdate(
                    p => p.Name,
                    new Character { Name = "Homer", TVShowId = 1 },
                    new Character { Name = "Marge", TVShowId = 1 },
                    new Character { Name = "Bart", TVShowId = 1 },
                    new Character { Name = "Lisa", TVShowId = 1 },
                    new Character { Name = "Maggie", TVShowId = 1 },
                    new Character { Name = "Michael Scott", TVShowId = 2 },
                    new Character { Name = "Dwight Schrute", TVShowId = 2 },
                    new Character { Name = "Jim Halpert", TVShowId = 2 },
                    new Character { Name = "Pam Beesly", TVShowId = 2 },
                    new Character { Name = "Leonard Hofstadter", TVShowId = 3 },
                    new Character { Name = "Sheldon Cooper", TVShowId = 3 },
                    new Character { Name = "Penny", TVShowId = 3 },
                    new Character { Name = "Howard Wolowitz", TVShowId = 3 },
                    new Character { Name = "Rajesh Koothrappali", TVShowId = 3 },
                    new Character { Name = "Bernadette", TVShowId = 3 },
                    new Character { Name = "Amy Farrah Fowler", TVShowId = 3 }
                    );
                db.SaveChanges();
            }
        }
    }
}
